<template>
  <div class="content">
    <div class="row">
      <div class="col-md-8">
        <edit-profile-form :model="model">
        </edit-profile-form>
      </div>
      <div class="col-md-4">
        <user-card :user="user"></user-card>
      </div>
    </div>
  </div>
</template>
<script>
import EditProfileForm from "./Profile/EditProfileForm.vue";
import UserCard from "./Profile/UserCard.vue";

export default{
  components:{
    EditProfileForm,
    UserCard
  },
  data() {
    return {
      model: {
        role: '',
        username: '',
        phone: '',
        email: '',
        qq: '',
        country: '',
        province: '',
        city: '',
        lastLoginTime: '',
        description: ''
      },
      user: {
        username: '',
        role: '',
        avatar: '',
        github: '',
        gitee: '',
        leetcode: ''
      }
    }
  },
  mounted: function () {
    this.getInformation()
  },
  methods:{
    getInformation(){
      var userInfo = this.$store.getters.userInfo
      var userOtherInfo = this.$store.getters.userOtherInfo
      this.model.role = userInfo.role.roleNameZh
      this.model.username = userInfo.nickName
      this.model.phone = userOtherInfo.phone
      this.model.email = userOtherInfo.email
      this.model.qq = userOtherInfo.qq
      this.model.country = userInfo.ipSource ? "内网登陆" : userInfo.ipSource.trim().split(/\s+/)[0]
      this.model.province = userInfo.ipSource ? "" : userInfo.ipSource.trim().split(/\s+/)[1]
      this.model.city = userInfo.ipSource ? "" : userInfo.ipSource.trim().split(/\s+/)[2]
      var date = new Date(userInfo.lastLoginTime);
      var Y = date.getFullYear() + '-';
      var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
      var D = date.getDate() + ' ';
      var h = date.getHours() + ':';
      var m = date.getMinutes() + ':';
      var s = date.getSeconds();
      this.model.lastLoginTime = Y+M+D+h+m+s;
      this.model.description = userOtherInfo.description
      this.user.username = userInfo.nickName
      this.user.role = userInfo.role.roleNameZh
      this.user.avatar = '/file/download/' + this.$store.getters.userInfo.avatar
      this.user.github = userOtherInfo.github
      this.user.gitee = userOtherInfo.gitee
      this.user.leetcode = userOtherInfo.leetcode
    }
  },

}
</script>
<style>
</style>
